package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDataDao;
import com.itheima.domain.Setmeal;
import com.itheima.service.BusinessDataService;
import com.itheima.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BusinessDataServiceImpl implements BusinessDataService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDataDao orderDataDao;
    @Override
    public Map<String, Object> findBusinessReport() throws Exception{

        String today=DateTimeUtil.getStringByDate(new Date(),"yyyy-MM-dd");
        //本周第一天
        String thisWeekFirstDay=DateTimeUtil.getStringByDate(DateTimeUtil.getDayOfWeek(new Date(),1),"yyyy-MM-dd");
        //本月第一天
        String thisMonthFirstDay=DateTimeUtil.getStringByDate(DateTimeUtil.firstDayOfMonth(new Date()),"yyyy-MM-dd");


        //新增会员数
        Integer todayNewMember=memberDao.findMemberCountByDay(today);
        //总会员数
        Integer totalMember=memberDao.findMemberCount();
        //本周新增会员数
        Integer thisWeekNewMember=memberDao.findMemberCountByWeek(thisWeekFirstDay);
        //本月新增会员数
        Integer thisMonthNewMember=memberDao.findMemberCountByMonth(thisMonthFirstDay);
        //今日预约数
        Integer todayOrderNewNumber=orderDataDao.findOrderCountByDay(today);
        //本周预约数
        Integer thisWeekOrderNumber=orderDataDao.findOrderCountByWeek(thisWeekFirstDay);
        //本月预约数
        Integer thisMonthOrderNumber=orderDataDao.findOrderCountByMonth(thisMonthFirstDay);
        //今日到诊数
        Integer todayVisitsNumber=orderDataDao.findVisitCountByDay(today);
        //本周到诊数
        Integer thisWeekVisitsNumber=orderDataDao.findVisitCountByWeek(thisWeekFirstDay);
        //本月到诊数
        Integer thisMonthVisitsNumber=orderDataDao.findVisitCountByMonth(thisMonthFirstDay);

        //热门套餐
        List<Map> hotSetmeal=orderDataDao.findMostOrderSetmeal();


        //备注
        List<Setmeal> remark=orderDataDao.findExplain();



        Map<String,Object> result=new HashMap<>();
        result.put("reportDate",today);
        result.put("todayNewMember",todayNewMember);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNewNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("remark",remark);
        result.put("hotSetmeal",hotSetmeal);

        return result;
    }
}
